import {createRouter,createWebHistory} from 'vue-router'
import Register from '../views/Register.vue'
import Login from '../views/Login.vue'
import CustomerBooking from '../views/CustomerBooking.vue'
import OrderConfirmation from '../views/OrderConfirmation.vue'
import MyOrders from '../views/MyOrders.vue'
import StaffRoomStatus from '../views/StaffRoomStatus.vue'
import AdminDashboard from '../views/AdminDashboard.vue'

const routes=[
    {
        path:'/',
        redirect:'/login'
    },
    {
        path:'/register',
        name:'register',
        component:Register
    },
    {
        path:'/login',
        name:'login',
        component:Login
    },
    {
        path:"/booking",
        name:'booking',
        component:CustomerBooking,
        // meta:{
        //     needLogin:true
        // }
    },
    {
        path:'/confirm',
        name:'confirm',
        component:OrderConfirmation,
        // meta:{
        //     needLogin:true
        // }
    },
    {
        path:'/orders',
        name:'orders',
        component:MyOrders,
        // meta:{
        //     needLogin:true
        // }
    },
    {
        path:'/status',
        name:'status',
        component:StaffRoomStatus,
        // meta:{
        //     needLogin:true
        // }
    },
    {
        path:'/admin',
        name:'admin',
        component:AdminDashboard,
        // meta:{
        //     needLogin:true
        // }
    }
]
const router = createRouter({
    history:createWebHistory(),
    routes:routes
})
router.beforeEach((to,from,next) => {
    if(to.meta.needLogin&&!sessionStorage.getItem('user')){
        alert('请先登录');
        next('/login');
        return;
    }
    next();
})
export default router;